package com.zb.select.controller;

import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjStorePositionService;
import com.zb.service.ZjStoreService;
import com.zb.service.ZjStoreTypeService;
import com.zb.store.service.ConStoreService;
import com.zb.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.regex.Pattern;

/**
 * @Author WEN
 * @Date 2023/11/3 0003
 **/
@Api(tags = "仓库类下拉接口")
@RestController
@RequestMapping("/store/select")
public class StoreSelectController {
    @Resource
    private ZjStoreService storeService;
    @Resource
    private ZjStoreTypeService storeTypeService;
    @Resource
    private ZjStorePositionService storePositionService;
    @Resource
    private ConStoreService conStoreService;

    @ApiOperation("仓库下拉列表查询")
    @PostMapping("/storePageSelect/{storeType}")
    public Result storePageSelect(HttpServletRequest request, @PathVariable @ApiParam(value = "仓库类型：0-内部仓库，1-服务商-外部仓库，2-工程师-外部仓库") String storeType,
                                  @RequestBody SelectVo selectVo) {
        Assert.isTrue(Pattern.matches("[0|1|2]", storeType), "仓库类型参数不合法");
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(conStoreService.storePageSelect(custAccId, storeType, selectVo));
    }

    @ApiOperation("根据仓库ID获取仓位下拉列表")
    @PostMapping("/storePositionPageSelect/{storeId}")
    public Result storePositionPageSelect(@PathVariable @ApiParam(value = "仓库ID", required = true) Long storeId, @RequestBody SelectVo selectVo) {
        return Result.success().data(storePositionService.storePositionPageSelect(storeId, selectVo));
    }

    @ApiOperation("仓库及人员地址下拉列表查询")
    @PostMapping("/storeEmpAddressPageSelect/{storeType}")
    public Result storeEmpAddressPageSelect(HttpServletRequest request, @PathVariable @ApiParam(value = "仓库类型：0-内部仓库，1-服务商-外部仓库，2-工程师-外部仓库") String storeType,
                                            @RequestBody SelectVo selectVo) {
        Assert.isTrue(Pattern.matches("[0|1|2]", storeType), "仓库类型参数不合法");
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(conStoreService.storeEmpAddressPageSelect(custAccId, storeType, selectVo));
    }

    @ApiOperation("出库仓库类型下拉列表查询")
    @PostMapping("/outStoreTypePageSelect")
    public Result outStoreTypePageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(storeTypeService.outStoreTypePageSelect(custAccId, 2, selectVo));
    }

    @ApiOperation("入库仓库类型下拉列表查询")
    @PostMapping("/inStoreTypePageSelect")
    public Result inStoreTypePageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(storeTypeService.outStoreTypePageSelect(custAccId, 1, selectVo));
    }


}
